package ciyuan.Gui.DamageShow;

import ciyuan.Gui.Particle.ParticleRegistry;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.network.PacketBuffer;
import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ParticleType;

public class DamageParticleData implements IParticleData {

    double speedX;
    double speedY;
    double speedZ;
    double x;
    double y;
    double z;

    int damage;

    public DamageParticleData(double x,double y,double z,double speedX, double speedY, double speedZ, int damage) {
        this.speedX = speedX;
        this.speedY = speedY;
        this.speedZ = speedZ;
        this.x=x;
        this.y=y;
        this.z=z;
        this.damage = damage;
    }

    @Override
    public ParticleType<?> getType() {
        return ParticleRegistry.damageParticle.get();
    }

    @Override
    public void writeToNetwork(PacketBuffer buffer) {
        buffer.writeDouble(x);
        buffer.writeDouble(y);
        buffer.writeDouble(z);
        buffer.writeDouble(speedX);
        buffer.writeDouble(speedY);
        buffer.writeDouble(speedZ);
        buffer.writeInt(damage);
    }

    @Override
    public String writeToString() {
        return "x=" + x + "y=" + y + "z=" + z + "damage=" + damage;
    }

    public static final IDeserializer<DamageParticleData> DESERIALIZER = new IDeserializer<DamageParticleData>()  {

        @Override
        public DamageParticleData fromCommand(ParticleType<DamageParticleData> p_197544_1_, StringReader reader) throws CommandSyntaxException {
            final int MIN_COLOUR = 0;
            final int MAX_COLOUR = 255;
            reader.expect(' ');
            double x = reader.readDouble();
            reader.expect(' ');
            double y = reader.readDouble();
            reader.expect(' ');
            double z = reader.readDouble();
            reader.expect(' ');
            int damage = reader.readInt();
            return new DamageParticleData(x,y,z,0.5,0.5,0.5,damage);
        }

        @Override
        public DamageParticleData fromNetwork(ParticleType<DamageParticleData> p_197543_1_, PacketBuffer buffer) {
            double x = buffer.readDouble();
            double y = buffer.readDouble();
            double z = buffer.readDouble();
            double speedX = buffer.readDouble();
            double speedY = buffer.readDouble();
            double speedZ = buffer.readDouble();
            int damage = buffer.readInt();
            return new DamageParticleData(x,y,z,speedX,speedY,speedZ,damage);
        }
    };

}
